package com.ternnetwork.configuration.controller.persistence;

import java.io.PrintWriter;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.ternnetwork.commons.model.http.BaseResponse;
import com.ternnetwork.commons.utils.PrintWriterUtils;
import com.ternnetwork.configuration.entity.persistence.IdGenerator;
import com.ternnetwork.configuration.service.persistence.IdGeneratorService;
import com.ternnetwork.persistence.page.Page;




@Controller@Scope("prototype")
@RequestMapping("/configuration/persistence/idgenerator/*")
public class IdGeneratorController {
	
	@SuppressWarnings("restriction")
	@Resource
	private IdGeneratorService  idGeneratorService;
	
	@RequestMapping("manage.htm")
	public ModelAndView manage(){
		return new ModelAndView("/WEB-INF/view/configuration/persistence/id_cenerator_manage.jsp");
	}
	
	@RequestMapping("add.htm")
	public @ResponseBody BaseResponse add(IdGenerator t){
		return idGeneratorService.idoAdd(t);
	}
	
	@RequestMapping("update.htm")
	public @ResponseBody BaseResponse update(IdGenerator t){
		return idGeneratorService.idoUpdate(t);
	}
	
	@RequestMapping("delete.htm")
	public @ResponseBody BaseResponse delete(long id){
		return idGeneratorService.idoDelete(id);
	}
	
	
	@RequestMapping("query.htm")
	public void query(PrintWriter out,HttpServletResponse response,String sort,String order,int limit, int offset,IdGenerator t){
		Page page=Page.createPage(limit, offset);
		PrintWriterUtils.printString(out, response, idGeneratorService.queryToJsonStr(t, page));
	}

}
